home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / yase.arc / EDIT0.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-12-13  |  4.0 KB  |  109 lines

  1. ******************************************************************
  2. * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
  3. * - Note: This is a real, live, actual, registered copyright,
  4. *   and should be treated as such. This source code is from
  5. *   the book "68000 Assembly Language", Krantz and Stanley,
  6. *   Addison-Wesley Publishing Company, Reading, MA, 1986.
  7. *   Permission granted by the authors for non-commercial use
  8. *   in programs released to the public domain, as long as this
  9. *   copyright notice remains attached and visible.
  10. *
  11. *****************************************************************
  12. * FILE I/O ROUTINES  
  13.  
  14.     xref    open_w,lineed,printf,read_in,prompt
  15.     xref    write_out,set_w,ask,cmd_w
  16.     xdef    readfile,writefile,filenm
  17.  
  18. #edit.h
  19.  
  20. *****************************************************************
  21. * Asks for a filename and reads it into current editing buffer
  22. * ENTRY:   A5.L points to edit buffer window descriptor file
  23. *          sets ed_err(a5) on error
  24. readfile:
  25.     movem.l    d1/d2/a0-a5,-(a7) Save caller's registers
  26.     move.l    #fprompt,a0    * setup prompt address
  27.     move.l    #filenm,a1    * setup input string address
  28.     bsr    ask        * output prompt
  29.     move.l    #filenm,a0    * setup for file read
  30.     move.l    b_gap(a5),a2    * save current start of gap
  31.     bsr    read_in        * try to read file
  32.     move.l    b_gap(a5),a3    * get new start of gap
  33.     move.l    a2,b_gap(a5)    * save gap start point
  34.  
  35.     move.l    a3,d1        * check how many chars read
  36.     sub.l    a2,d1        * d1 is now number of chars read
  37.     move.l    e_gap(a5),a2    * get end of gap address
  38.     bra    loop_test    * this is a check-first loop
  39. loop_point:
  40.     move.b    -(a3),-(a2)    * transfer chars to end of gap
  41. loop_test:
  42.     dbra    d1,loop_point
  43.     move.l    a2,e_gap(a5)    * save new gap end address
  44.     tst.w    d0        * check if file was read
  45.     beq    exit        * just leave if we read it
  46.     cmp.b    #1,d0        * is it file-not-found error?
  47.     beq    sk0_rf        * yes, go tell user
  48.     move.w    #5,ed_err(a5)    * was file-too-large error
  49.     bra    exit        * print error
  50. sk0_rf:
  51.     move.w    #6,ed_err(a5)    * new file message address
  52. exit:
  53.     movem.l    (a7)+,d1/d2/a0-a5 * restore caller's registers
  54.     rts
  55. fprompt:
  56.     dc.b    'Input Filename: ',0
  57.     dc.w    0
  58. *****************************************************************
  59. * WRITEFILE - writes a block to disk
  60. *  ENTRY: A1.L points to start of data buffer
  61. *         D1.W holds number of bytes to write
  62. *  EXIT:  D0.W = 0 for success
  63. *              = 1 for failure
  64. writefile:
  65.     movem.l    d1/d2/a0/a5,-(a7) * Save caller's registers
  66.     move.l    #cmd_w,a5    * get command I/O window desc.
  67.     bsr    open_w        * open command window
  68.     move.w    w_ulcy(a5),-(a7) * setup prompt Y position
  69.     move.w    w_ulcx(a5),-(a7) * setup prompt X position
  70.     move.l    #wprompt,-(a7)    * setup prompt address
  71.     bsr    printf        * output prompt
  72.     addq.l    #8,a7        * fix the stack
  73.     move.w    w_ulcx(a5),d0    * input line X position
  74.     add.w    #17,d0        * new X position for input line
  75.     move.w    w_lrcx(a5),d2    * calculate max. line length for
  76.     sub.w    d0,d2        *... input line editor
  77.     move.w    d2,-(a7)    * push max editing lines
  78.     move.w    d0,-(a7)    * push starting screen column
  79.     move.w    w_ulcy(a5),-(a7) * push screen row
  80.     move.l    #filenm,-(a7)    * push string address
  81.     bsr    lineed        * get input line with filename
  82.     add.l    #10,a7        * pop lineed parameters
  83.     
  84.     move.l    #filenm,a0    * setup for file write
  85.     bsr    write_out    * try to read file
  86.     tst.w    d0        * check if file was written
  87.     beq    wexit        * just leave if we wrote it
  88.     move.w    w_ulcy(a5),-(a7) * push message y position - 1
  89.     addq.w    #1,(a7)        * adjust for correct position
  90.     move.w    w_ulcx(a5),-(a7) * push x position
  91.     move.l    #cant_rite,-(a7) * push message string address
  92.     bsr    printf        * tell user
  93.     addq.l    #8,a7        * fix stack
  94.     move.w    #1,d0        * set error code
  95. wexit:
  96.     movem.l    (a7)+,d1/d2/a0/a5 * restore caller's registers
  97.     rts
  98. wprompt:
  99.     dc.b    '%vOutput Filename: ',0
  100. cant_rite:
  101.     dc.b    '%v* * * Error writing file * * *',0
  102.     dc.w    0
  103. *****************************************************************
  104.     bss
  105. filenm:    ds.b    80        * current filename buffer
  106.  
  107.     end
  108.